package com.hspedu.exception_;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/30
 * @time 23:30
 */
public class CustomException {
    public static void main(String[] args) {
        Person person = new Person(200);
        if (!(person.age >= 18 && person.age <= 120)){
            throw new AgeException("年龄需要在18-120之间");
        }
        System.out.println("你的年龄范围正确");
    }
}

class AgeException extends RuntimeException{
    public AgeException(String message) {
        super(message);
    }
}

class Person{
    public int age;

    public Person(int age) {
        this.age = age;
    }
}
